<%@ Page Language="C#" MasterPageFile="~/site.master" AutoEventWireup="true" CodeFile="MateriasABM.aspx.cs" Inherits="Materias_MateriasABM" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    &nbsp;&nbsp;

        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
            CellPadding="4" DataKeyNames="IdMateria" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display."
            ForeColor="#333333" GridLines="None" AllowSorting="True" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <Columns>
                <asp:BoundField DataField="MateriaDesc" HeaderText="Materia" SortExpression="MateriaDesc" />
                <asp:BoundField DataField="Descripcion" HeaderText="Tipo Materia" SortExpression="Descripcion" />
                <asp:BoundField DataField="Orden" HeaderText="Orden" SortExpression="Orden" />
                <asp:CommandField ShowSelectButton="True" SelectText="Ver" />
            </Columns>
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <EmptyDataTemplate>
                No existen registros
            </EmptyDataTemplate>
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#999999" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        </asp:GridView>
        <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="IdMateria"
            DataSourceID="SqlDataSource2" Height="50px" Width="125px" OnPageIndexChanging="DetailsView1_PageIndexChanging" OnModeChanged="DetailsView1_ModeChanged">
            <Fields>
                <asp:BoundField DataField="IdMateria" HeaderText="IdMateria" InsertVisible="False"
                    ReadOnly="True" SortExpression="IdMateria" />
                <asp:BoundField DataField="MateriaDesc" HeaderText="MateriaDesc" SortExpression="MateriaDesc" />
                <asp:TemplateField HeaderText="TipoMateria" SortExpression="TipoMateria">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="sqlTipoMateria"
                            DataTextField="Descripcion" DataValueField="IdTipoMateria" SelectedValue='<%# Bind("TipoMateria") %>'>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="sqlTipoMateria"
                            DataTextField="Descripcion" DataValueField="IdTipoMateria" SelectedValue='<%# Bind("TipoMateria") %>'>
                        </asp:DropDownList>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="sqlTipoMateria"
                            DataTextField="Descripcion" DataValueField="IdTipoMateria" SelectedValue='<%# Bind("TipoMateria") %>' Enabled="False">
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Orden" HeaderText="Orden" SortExpression="Orden" />
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" />
            </Fields>
        </asp:DetailsView>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    &nbsp; &nbsp;&nbsp;
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ColegiosConnectionString %>"
            ProviderName="<%$ ConnectionStrings:ColegiosConnectionString.ProviderName %>"
            SelectCommand="SELECT  Materia.IdMateria, Materia.MateriaDesc, TipoMateria.Descripcion, Materia.Orden  FROM         Materia INNER JOIN TipoMateria ON Materia.TipoMateria = TipoMateria.IdTipoMateria"
            DeleteCommand="DELETE FROM [Materia] WHERE [IdMateria] = @IdMateria" 
            InsertCommand="INSERT INTO [Materia] ([MateriaDesc], [TipoMateria], [Orden]) VALUES (@MateriaDesc, @TipoMateria, @Orden)"
            UpdateCommand="UPDATE [Materia] SET [MateriaDesc] = @MateriaDesc, [TipoMateria] = @TipoMateria, [Orden] = @Orden WHERE [IdMateria] = @IdMateria">
            <DeleteParameters>
                <asp:Parameter Name="IdMateria" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="MateriaDesc" Type="String" />
                <asp:Parameter Name="TipoMateria" Type="String" />
                <asp:Parameter Name="Orden" Type="Int32" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="MateriaDesc" Type="String" />
                <asp:Parameter Name="TipoMateria" Type="String" />
                <asp:Parameter Name="Orden" Type="Int32" />
                <asp:Parameter Name="IdMateria" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
    &nbsp; &nbsp;
        <asp:SqlDataSource ID="sqlTipoMateria" runat="server" ConnectionString="<%$ ConnectionStrings:ColegiosConnectionString %>"
            SelectCommand="SELECT [IdTipoMateria], [Descripcion] FROM [TipoMateria]"></asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ColegiosConnectionString %>"
            SelectCommand="SELECT IdMateria, MateriaDesc, TipoMateria, Orden FROM Materia WHERE (IdMateria = @idmateria)" DeleteCommand="DELETE FROM Materia WHERE (IdMateria = @idmateria)" InsertCommand="INSERT INTO Materia(MateriaDesc, TipoMateria, Orden) VALUES (@MateriaDesc, @TipoMateria, @Orden)" UpdateCommand="UPDATE Materia SET MateriaDesc = @MateriaDesc , TipoMateria = @TipoMateria, Orden = @Orden where idmateria = @idmateria">
            <SelectParameters>
                <asp:ControlParameter ControlID="GridView1" Name="idmateria" PropertyName="SelectedValue" />
            </SelectParameters>
            <DeleteParameters>
                <asp:Parameter Name="idmateria" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="MateriaDesc" />
                <asp:Parameter Name="tipomateria" />
                <asp:Parameter Name="orden" />
                <asp:Parameter Name="idmateria" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="MateriaDesc" />
                <asp:Parameter Name="tipomateria" />
                <asp:Parameter Name="orden" />
            </InsertParameters>
        </asp:SqlDataSource>
</asp:Content>